﻿using System;
using System.Collections;
using System.Collections.Generic;
namespace Library.Util {
	/// <summary>
	/// Implement IList by List. all method is virtual
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class ListBase<T> : IList<T>, IDisposable {
		protected ListBase() {
			InnerList = new List<T>();
		}
		protected readonly List<T> InnerList;
		public virtual IEnumerator<T> GetEnumerator() {
			return InnerList.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator() {
			return GetEnumerator();
		}
		/// <summary>
		/// Call insert method with index is Count
		/// </summary>
		/// <param name="item"></param>
		public virtual void Add(T item) {
			InnerList.Add(item);
		}

		public virtual void Clear() {
			InnerList.Clear();
		}

		public virtual bool Contains(T item) {
			return InnerList.Contains(item);
		}

		public virtual void CopyTo(T[] array, int arrayIndex) {
			InnerList.CopyTo(array, arrayIndex);
		}

		public virtual bool Remove(T item) {
			return InnerList.Remove(item);
		}

		public virtual int Count {
			get { return InnerList.Count; }
		}

		public virtual bool IsReadOnly {
			get { return false; }
		}

		public virtual int IndexOf(T item) {
			return InnerList.IndexOf(item);
		}

		public virtual void Insert(int index, T item) {
			InnerList.Insert(index, item);
		}



		public virtual void RemoveAt(int index) {
			InnerList.RemoveAt(index);
		}

		public virtual T this[int index] {
			get { return InnerList[index]; }
			set { InnerList[index] = value; }
		}

		public virtual void Dispose() {
			Clear();
		}
	}
}
